package com.z.action;

import com.z.base.BaseAction;
import com.z.base.LoginUser;
import com.z.service.AuthenticationService;
import com.z.vo.AuthenticationForm;

@SuppressWarnings("serial")
public class AuthenticationAction extends BaseAction {
	private AuthenticationForm authenticationForm = new AuthenticationForm();

	@Override
	public Object getModel() {
		return authenticationForm;
	}

	public String execute() {
		if (getLoginUser() != null) {
			return "already_login";
		} else {
			return SUCCESS;
		}
	}

	public String login() {
		if (getLoginUser() != null) {
			return "already_login";
		}
		LoginUser loginUser = AuthenticationService.getInstance()
				.findByPassword(authenticationForm);
		if (loginUser == null) {
			return "error";
		}
		session.put(LOGIN_USER_SESSION_ID, loginUser);
		return "ok";
	}
}
